﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace DataAcces
{
    public static class HelperDA
    {
        public static string ToExecuteCommand<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, string storeprocedureName)
        {
            if (dictionary == null)
            {
                return storeprocedureName;
            }
            return storeprocedureName + " " + string.Join(",", dictionary.Select(kv => "@" + kv.Key.ToString()).ToArray());
        }

        public static SqlParameter[] ToSqlParameters<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
        {
            if (dictionary == null)
            {
                return null;
            }
            IList<SqlParameter> _lstparameter = new List<SqlParameter>();
            foreach (var kv in dictionary)
            {
                _lstparameter.Add(new SqlParameter("@" + kv.Key.ToString(), kv.Value.ToString()));
            }

            if (_lstparameter.Count == 0)
            {
                return null;
            }
            return _lstparameter.ToArray();
        }
    }
}
